// File Name: usart_init.c
// Author: kukukukuku~
// Date: 2024-12-21

#include "apm32f00x_gpio.h"
#include "apm32f00x_misc.h"
#include "apm32f00x_usart.h"
#include "./USART/inc/usart_init.h"
#include "./USART/inc/usart_macros.h"


/**
 * @brief   USART USART配置
 * @param   None
 * @retval  None
 * @note    静态
*/
static void usart_usart_config(void)
{
    USART_Config_T usartConfig = 
    {
        .baudRate   = USART_USART_BAUDRATE,
        .mode       = USART_USART_MODE,
        .interrupt  = USART_INT_NONE,
        .parity     = USART_USART_PARITY_BIT,
        .stopBits   = USART_USART_STOP_BIT,
        .wordLength = USART_USART_DATA_BIT,
    };
    
    USART_Config(USART_USART, &usartConfig);
    USART_ClearStatusFlag(USART_USART, USART_FLAG_RXBNE);
    USART_EnableInterrupt(USART_USART, USART_INT_RX);
    USART_EnableInterrupt(USART_USART, USART_INT_IDLE);
    NVIC_EnableIRQRequest(USART_USART_RX_IRQ, 0);
    USART_Enable(USART_USART);
}


/**
 * @brief   USART初始化
 * @param   None
 * @retval  None
 * @note    None
*/
void usart_init(void)
{
    usart_usart_config();
}
